def add(x, y):
    print(x + y)
    return x + y


def subtract(x, y):
    print(x - y)
    return x - y


def mul(x, y):
    print(x * y)
    return x * y


def divi(x, y):
    if y == 0:
        print("除数不能为0！")
    else:
        # format(*, '.*f') * 表示数字，取小数点后几位,这里保留3位小数
        print(format((x / y), '.3f'))
        return x / y


if __name__ == '__main__':
    print('简单的加减乘除计算')
    # x = float(input("请输入X的值："))
    numx = input("请输入X的值：")
    try:
        x = float(numx)
        opera = input("请输入运算符（+、-、*、/）：")
        numy = input("请输入y的值：")
        try:
            y = float(numy)
            if opera == '+':
                add(x, y)
            elif opera == '-':
                subtract(x, y)
            elif opera == '*':
                mul(x, y)
            elif opera == '/':
                divi(x, y)
            else:
                print("请输入规定的运算符（+、-、*、/）")
        except ValueError:
            print("请输入正确的数字")
    except ValueError:
        print("请输入数字！")
